import { ComponentType } from '../types/component';
import { FieldType } from '../types/model';
import { PageType, LayoutType } from '../types/page';
import type { Component, Page, Model } from '../types/index';

/**
 * 学生信息管理系统模板
 */

// 学生模型
export const studentModel: Model = {
  name: 'student',
  label: '学生',
  fields: [
    { name: 'id', type: FieldType.STRING, label: '学号', required: true, isKey: true },
    { name: 'name', type: FieldType.STRING, label: '姓名', required: true },
    { name: 'gender', type: FieldType.ENUM, label: '性别', options: [
      { label: '男', value: 'male' },
      { label: '女', value: 'female' }
    ]},
    { name: 'age', type: FieldType.NUMBER, label: '年龄' },
    { name: 'class', type: FieldType.STRING, label: '班级', required: true },
    { name: 'department', type: FieldType.STRING, label: '院系' },
    { name: 'admissionDate', type: FieldType.DATE, label: '入学日期' },
    { name: 'phone', type: FieldType.STRING, label: '联系电话' },
    { name: 'email', type: FieldType.STRING, label: '电子邮箱' },
    { name: 'address', type: FieldType.STRING, label: '家庭住址' }
  ]
};

// 课程模型
export const courseModel: Model = {
  name: 'course',
  label: '课程',
  fields: [
    { name: 'id', type: FieldType.STRING, label: '课程编号', required: true, isKey: true },
    { name: 'name', type: FieldType.STRING, label: '课程名称', required: true },
    { name: 'credit', type: FieldType.NUMBER, label: '学分', required: true },
    { name: 'teacher', type: FieldType.STRING, label: '授课教师' },
    { name: 'description', type: FieldType.STRING, label: '课程描述' },
    { name: 'semester', type: FieldType.STRING, label: '学期' }
  ]
};

// 学生列表页组件
const studentListComponents: Component[] = [
  // 页面标题
  {
    id: 'header_title',
    name: '页面标题',
    type: ComponentType.TEXT,
    props: {
      text: '学生信息管理系统',
      style: { marginBottom: '20px', fontSize: '24px', fontWeight: 'bold' }
    },
    layout: { x: 0, y: 0, w: 12, h: 1, minW: 4, minH: 1 },
    events: []
  },
  // 搜索栏
  {
    id: 'search_bar',
    name: '搜索栏',
    type: ComponentType.SEARCH_BAR,
    props: {
      placeholder: '搜索学生...',
      style: { marginBottom: '16px' }
    },
    layout: { x: 0, y: 1, w: 6, h: 1, minW: 4, minH: 1 },
    events: []
  },
  // 添加按钮
  {
    id: 'add_button',
    name: '添加按钮',
    type: ComponentType.BUTTON,
    props: {
      text: '添加学生',
      type: 'primary',
      style: { marginBottom: '16px', marginLeft: '8px' }
    },
    layout: { x: 6, y: 1, w: 2, h: 1, minW: 2, minH: 1 },
    events: []
  },
  // 学生表格
  {
    id: 'students_table',
    name: '学生表格',
    type: ComponentType.TABLE,
    props: {
      columns: [
        { title: '学号', dataIndex: 'id', key: 'id' },
        { title: '姓名', dataIndex: 'name', key: 'name' },
        { title: '性别', dataIndex: 'gender', key: 'gender' },
        { title: '年龄', dataIndex: 'age', key: 'age' },
        { title: '班级', dataIndex: 'class', key: 'class' },
        { title: '院系', dataIndex: 'department', key: 'department' },
        { title: '入学日期', dataIndex: 'admissionDate', key: 'admissionDate' },
        { 
          title: '操作', 
          key: 'action',
          render: 'text: "查看 | 编辑 | 删除"' 
        }
      ],
      dataSource: [
        {
          id: '2023001',
          name: '张三',
          gender: '男',
          age: 20,
          class: '计算机科学与技术1班',
          department: '信息学院',
          admissionDate: '2023-09-01'
        },
        {
          id: '2023002',
          name: '李四',
          gender: '女',
          age: 19,
          class: '软件工程2班',
          department: '信息学院',
          admissionDate: '2023-09-01'
        }
      ],
      pagination: { pageSize: 10 },
      style: { width: '100%' }
    },
    layout: { x: 0, y: 2, w: 12, h: 8, minW: 6, minH: 4 },
    events: []
  }
];

// 学生详情页组件
const studentDetailComponents: Component[] = [
  // 页面标题
  {
    id: 'detail_header_title',
    name: '页面标题',
    type: ComponentType.TEXT,
    props: {
      text: '学生详情',
      style: { marginBottom: '20px', fontSize: '24px', fontWeight: 'bold' }
    },
    layout: { x: 0, y: 0, w: 12, h: 1, minW: 4, minH: 1 },
    events: []
  },
  // 返回按钮
  {
    id: 'back_button',
    name: '返回按钮',
    type: ComponentType.BUTTON,
    props: {
      text: '返回列表',
      style: { marginBottom: '16px' }
    },
    layout: { x: 0, y: 1, w: 2, h: 1, minW: 2, minH: 1 },
    events: []
  },
  // 学生信息表单
  {
    id: 'student_form',
    name: '学生表单',
    type: ComponentType.FORM,
    props: {
      layout: 'horizontal',
      labelCol: { span: 4 },
      wrapperCol: { span: 16 },
      fields: [
        { name: 'id', label: '学号', type: 'input', required: true },
        { name: 'name', label: '姓名', type: 'input', required: true },
        { name: 'gender', label: '性别', type: 'select', options: [
          { label: '男', value: 'male' },
          { label: '女', value: 'female' }
        ], required: true },
        { name: 'age', label: '年龄', type: 'input-number' },
        { name: 'class', label: '班级', type: 'input', required: true },
        { name: 'department', label: '院系', type: 'input' },
        { name: 'admissionDate', label: '入学日期', type: 'date-picker' },
        { name: 'phone', label: '联系电话', type: 'input' },
        { name: 'email', label: '电子邮箱', type: 'input' },
        { name: 'address', label: '家庭住址', type: 'textarea' }
      ],
      style: { width: '100%' }
    },
    layout: { x: 0, y: 2, w: 12, h: 10, minW: 6, minH: 6 },
    events: []
  },
  // 保存按钮
  {
    id: 'save_button',
    name: '保存按钮',
    type: ComponentType.BUTTON,
    props: {
      text: '保存',
      type: 'primary',
      style: { marginRight: '8px' }
    },
    layout: { x: 4, y: 12, w: 2, h: 1, minW: 2, minH: 1 },
    events: []
  },
  // 取消按钮
  {
    id: 'cancel_button',
    name: '取消按钮',
    type: ComponentType.BUTTON,
    props: {
      text: '取消'
    },
    layout: { x: 6, y: 12, w: 2, h: 1, minW: 2, minH: 1 },
    events: []
  }
];

// 页面定义
export const pages: Record<string, Page> = {
  list: {
    id: 'list',
    name: '学生列表',
    path: '/students',
    type: PageType.LIST,
    layoutType: LayoutType.GRID,
    components: studentListComponents
  },
  detail: {
    id: 'detail',
    name: '学生详情',
    path: '/students/:id',
    type: PageType.DETAIL,
    layoutType: LayoutType.GRID,
    components: studentDetailComponents
  }
};

// 导出完整模板
export default {
  name: '学生信息管理系统',
  description: '基础的学生信息管理系统，包含学生信息的增删改查',
  models: {
    student: studentModel,
    course: courseModel
  },
  pages
};
